package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 根据id，用户id，套餐id，用户id，菜品id和菜品风味从购物车表查询购物车信息
     * @param shoppingCart
     * @return
     */
    ShoppingCart getUnique(ShoppingCart shoppingCart);

    /**
     * 根据id，用户id和套餐id或用户id和菜品id从购物车表查询购物车信息
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> getList(ShoppingCart shoppingCart);

    /**
     * 保存一条购物车信息表到购物车表
     * @param shoppingCart
     */
    @Insert("insert shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void save(ShoppingCart shoppingCart);

    /**
     * 根据id从购物车信息表修改购物车信息
     * @param build
     */
    void update(ShoppingCart build);

    /**
     * 根据用户id从购物车信息表清空购物车信息
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void delByUserId(Long userId);

    /**
     * 根据id从购物车信息表清空购物车信息
     * @param userId
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void delById(Long id);
}
